package com.jielihaofeng.chat.constants;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * 时期类型
 */
public enum PeriodTypeEnum {

    TODAY("0", "今天"),
    YESTERDAY("yesterday", "昨天"),
    THIS_WEEK("this_week", "本周"),
    THIS_MONTH("this_month", "本月"),
    THIS_YEAR("this_year", "今年"),
    EARLIER("earlier", "更早"),
    UNKNOWN("unknown", "未知宇宙时间"),
    ;

    private final String code;
    private final String name;

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    PeriodTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 通过code获取枚举
     *
     * @param code 编码
     * @return 枚举
     */
    public static PeriodTypeEnum getByCode(String code) {
        return Arrays.stream(PeriodTypeEnum.values())
                .filter(messageTypeEnum -> StringUtils.equals(messageTypeEnum.getCode(), code))
                .findFirst()
                .orElse(null);
    }

}
